package com.wyf.android.advance.test

import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.wyf.android.advance.R
import com.wyf.android.baselib.util.LogUtil
import kotlinx.android.synthetic.main.activity_test.*
import java.io.File

class TestActivity : AppCompatActivity() {
    private val list = ArrayList<TestViewData>()
    private var test = TestViewData("aaaaaa", 666, SimpleData("dddddd", "eeeeeee"))
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)

        repeat(50) {
            list.add(TestViewData("a${it}", it, SimpleData("d${it}", "e${it}")))
        }
        list.add(test)

        rv_test.apply {
            layoutManager = LinearLayoutManager(this@TestActivity)
            adapter = TestAdapter()
        }
        (rv_test.adapter as TestAdapter).setData(list)
        v_notify_switch.setOnClickListener {
            v_notify_switch.isSelected = !v_notify_switch.isSelected
        }

        val sp = getSharedPreferences("testsp", MODE_PRIVATE)
        val testvalue = sp.getBoolean("test",false)
        LogUtil.d("---",testvalue.toString())
        sp.edit().putBoolean("test",true).apply()
        val testvalue1 = sp.getBoolean("test",false)
        LogUtil.d("---1",testvalue1.toString())

        sp.edit().clear().apply()
        val testvalue2 = sp.getBoolean("test",false)
        LogUtil.d("---2",testvalue2.toString())
        val s = filesDir.parentFile.absolutePath + File.separator +"shared_prefs"+File.separator+ "testsp.xml"
        val f = File(s)
//        LogUtil.d("---3","s=$s,s.e=${f.exists()}")
//        if (f.exists()){
//            f.delete()
//        }
        LogUtil.d("---4","s=$s,s.e=${f.exists()}")

//        lv_test2.adapter = Test1Adapter()
//        (lv_test2.adapter as Test1Adapter).setData(list)
    }
    val handler = Handler { msg ->
        val m = Message.obtain(msg)
        true
    }

    fun test(view: View) {
        list[15].a = "15151515"
        list[16].c.d = "161616"
        list.removeAt(33)
    }

    fun test2(view: View) {
        list.add(test)
        test.a = "hhhhhh"
    }
}